// spawner.txt - Only exists to create creatures. Never moves or attacks. 
// If it sees a foe, it summons a creature. Does so at most once every 3 rounds.
// Cells 0 - 3 - Numbers of creatures to spawn. if 0, no use.
// Cell 4,5 - Stuff done flag to set when spawner is killed. If both are 0, no 
// flag set.
// Cell 6 - talking cell

begincreaturescript;

variables;

short r1;
short last_spawn;

body;

beginstate INIT_STATE;
	set_name(ME,"Slime Factory");
	
	set_walk_speed(ME,0);
	last_spawn = get_current_tick();
	break;

beginstate DEAD_STATE;
	inc_flag(23,12,1);
	sf(23,get_memory_cell(5),1);
	if (gf(23,13) == 0) {
		sf(23,13,1);
		ok_dlog(50,2);
		}
break;

beginstate START_STATE; 
	// see if target is visible
	get_foe_target(ME,12,0);
	
	if ((target_ok()) && (dist_to_party() <= 12)) {
		if ((tick_difference(last_spawn,get_current_tick()) > 0) && 
		  ((get_ran(1,0,100) < 90) || (friends_nearby(4) == 0))) {
			r1 = get_ran(1,0,3);
			if (get_memory_cell(r1) > 0) {
				if (summon_creature(get_memory_cell(r1))) {
					print_named_str(ME,"creates a new foe!");
					set_summon_level(get_memory_cell(r1),1);
					place_particle_num(get_memory_cell(r1),1051,1,8);
					set_attack_bonus(get_memory_cell(r1),10 * difficulty());
					run_char_animation(3,1,35);	
					pc_heard_sound_delay(171,100);	
					
					last_spawn = get_current_tick();
					

					}
				}
			}
		}
break;

beginstate TALKING_STATE;
	if (get_memory_cell(6) == 0) {
		print_str("Talking: It doesn't respond. It can't talk.");
		end();
		}
	begin_talk_mode(get_memory_cell(6));
break;